package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.attr;

import com.iwhalecloud.bss.kite.client.vo.scene.CommonAttrVO;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosUserDTO;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalServiceOfferConsts;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.iwhalecloud.bss.kite.web.context.KiteWebContext;
import com.iwhalecloud.bss.kite.web.service.accept.attr.handler.AbstractAttrHandler;
import com.ztesoft.bss.common.util.SpringUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class GroupUserIdHandler extends AbstractAttrHandler {

    @Override
    public void init(CommonAttrVO commonAttr) {
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        String sceneInstId = KiteWebContext.getContext().getCurrentSceneInstId();
        KiteSceneInst kiteSceneInst = querySceneInstService.getSceneInst(sceneInstId);
        Map<String, Object> map = querySceneInstService.getExtParameter(sceneInstId);
        String serviceOfferId = kiteSceneInst.getServiceOfferId();
        if(KiteStringUtils.equalsAny(serviceOfferId, LocalServiceOfferConsts.SERVICE_OFFER_COLLECTION_GROUP_ADD)){
            commonAttr.setShowType("D");
            if(KiteMapUtils.isNotEmpty(map)){
                List <KitePosUserDTO> kitePosUserDTOs = (List<KitePosUserDTO>) map.get("userInfos");
                if(KiteListUtils.isNotEmpty(kitePosUserDTOs)){
                    KitePosUserDTO kitePosUserDTO = kitePosUserDTOs.get(0);
                    String userId = kitePosUserDTO.getUserId();
                    commonAttr.setValue(userId);
                    setCommonAttr(commonAttr);
                }

            }
        }
    }

}
